package com.fbee.smartcommunities.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fbee.smartcommunities.entity.Complains;
import com.fbee.smartcommunities.entity.Visitor;
import com.fbee.smartcommunities.mapper.ComplainsMapper;
import com.fbee.smartcommunities.service.ComplainsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 汪佳泉
 * @since 2024-08-22
 */
@Service
public class ComplainsServiceImpl extends ServiceImpl<ComplainsMapper, Complains> implements ComplainsService {

    @Override
    public Page<Complains> getPage(Integer pageNo, Integer pageSize, String target,Boolean state) {
        Page<Complains> page = new Page<>(pageNo, pageSize);
        QueryWrapper<Complains> queryWrapper = new QueryWrapper<>();
        if(state){
            queryWrapper.eq("status",0);
        }
        if(target != null){
            return this.page(page,queryWrapper.eq("target",target));
        } else {
            return this.page(page,queryWrapper);
        }
    }

    @Override
    public Boolean changeState(Long id, Boolean state, String key) {
        return this.update(new UpdateWrapper<Complains>().set("status",!state).eq("id",id));
    }

}
